function dividing(module) {
    console.log('==========================================');
    console.log(module + ':');
    console.log('');
}

dividing('类声明');
// 类声明
class User {
    // 默认值
    constructor(name = '', age = 1) {
        this.name = name;
        this.age = age;
    }
}
var Jack = new User('Jack', 25);
console.log(Jack);

dividing('类表达式(匿名)');
// 类表达式(匿名)
var Polygon = class {
    constructor(num = 3) {
        this.side = num;
    }
};
var quadrilateral = new Polygon(4);
console.log(quadrilateral);

dividing('类表达式(命名)');
// 类表达式(命名)
var Animal = class XX {
    constructor(name = '') {
        this._name = name;
        console.log('inside', XX); // 类名只有在类体内部才能访问到
    }

    set name(name) {
        this._name = name;
    }
};
var dog = new Animal('WangCai');
// var dog = new XX('WangCai');  // ReferenceError
console.log(dog);

dividing('原型方法');
// 原型方法
class Dog {
    constructor(name, color) {
        this.name = name;
        this.color = color;
    }

    get hi() {
        console.log('getter');
        console.log(this.desc());
    }

    set hi(desc) {
        console.log('setter');
        this._desc = desc;
    }

    desc() {
        var desc = 'name: ' + this.name + ', color: ' + this.color;
        if (this._desc) {
            desc = this._desc;
        }
        return desc;
    }
}
let d = new Dog('WangCai', 'gray');
// d.hi = 'hello';
d.hi;

dividing('静态方法');
// 静态方法
// static 关键字用来定义类的静态方法。 静态方法是指那些不需要对类进行实例化，使用类名就可以直接访问的方法。静态方法经常用来作为工具函数。
class Point {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }

    static distancs(a, b) {
        const dx = a.x - b.x;
        const dy = a.y - b.y;

        return Math.sqrt(dx * dx + dy * dy);
    }
}
const p1 = new Point(0, 0);
const p2 = new Point(1, 0);
console.log(Point.distancs(p1, p2));

dividing('继承');
// 继承
class Cat extends Animal {
    constructor(name, color) {
        super(name);
        this.color = color;
    }
}
const animal = new Animal('xx');
const c = new Cat('Tom', 'yellow');
animal.name = 'name';
console.log(animal);
c.name = 'asd';
console.log(c);